package com.itheima.service;

import com.itheima.domain.Classes;
import com.itheima.domain.Student;
import com.itheima.mapper.ClassesMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class ClassesServiceTest {

    private ClassesMapper dao;
    private SqlSession sqlSession;

    @Before
    public void init() throws IOException {
        InputStream in = Resources.getResourceAsStream("MybatisConfig.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
        sqlSession = factory.openSession();
        // 获取Dao代理对象
        // AccountDao mapper = new AccountDaoImpl();
        dao = sqlSession.getMapper(ClassesMapper.class);
    }


    @After
    public void destroy() throws IOException {
        // 提交事务
        sqlSession.commit();

        // 释放资源
        sqlSession.close();
    }


    @Test
    public void findAll() {

        List<Classes> classesList = dao.findAll();
        for (Classes classes : classesList) {
           System.out.println(classes);
          //  System.out.println(classes.getCname());
        }
    }

}
